//
//  ZYXClassificationViewController.m
//  RuiBeiKang
//
//  Created by iOS开发1 on 2019/1/2.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXClassificationViewController.h"

#import "ZYXHomeModel.h"
#import "ZYClassCell.h"
#import "ZYXClassificationModel.h"
#import "ZYXClassVC.h"
@interface ZYXClassificationViewController ()
@property (strong,nonatomic) NSMutableArray *dataArr;
@end

@implementation ZYXClassificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitle:@"分类"];
}
#pragma mark MainUI
-(void)setupViews{
    self.tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationBar_Height-TabBar_Height);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"ZYClassCell" bundle:nil] forCellReuseIdentifier:@"ZYClassCell"];
    [self.view addSubview:self.tableView];
    
}
#pragma mark 加载数据
- (void)loadData {

    [NetWork GETWithUrlString:kInterfaceAllUrl(PATH_FenleiIndex) parmas:nil successBloock:^(NSDictionary *responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"code"] isEqualToNumber:@200]) {
            NSArray *modelArr = [ZYXClassificationModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
            self.dataArr = [NSMutableArray arrayWithArray:modelArr];
            [self.tableView reloadData];
        }else{
            [JKToast showWithText:responseObject[@"message"]];
        }
   
    } failureBlock:^(NSError *error) {
        
    }];
}
#pragma mark tableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZYClassCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZYClassCell"];
    cell.model = self.dataArr[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 51;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击查看更多");
    ZYXClassificationModel *model = self.dataArr[indexPath.row];
    ZYXClassVC *vc = [[ZYXClassVC alloc]init];
    vc.title = model.title;
    vc.mid = model.uid;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark 懒加载
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
@end
